<?php
// +----------------------------------------------------------------------
// | YikeCMS
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://zhuizhan.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: Doo <yws_sky@163.com> | <Qq:1151414552>
// +----------------------------------------------------------------------
namespace Home\Controller;
use Org\Yike\Category;
use Think\Controller;
class CommonController extends Controller {
    protected $siteId;
    private $siteseo;
    public function _initialize(){
        $this->cotroller = strtolower(CONTROLLER_NAME);
        $this->getSiteId();
       //网站配置
        $where =array('site_id'=>$this->siteId,'name'=>'site');
        $setting = $setting = M('setting')->where($where)->select();
        $arr = array();
        foreach($setting as $s){
            $arr[$s['name']] = json_decode($s['data'],true);
        }

       // $this->seo= array('title'=>$arr['site']['seo_title'].'_'.$arr['site']['title'],'keys'=>$arr['site']['seo_keys'],'desc'=>$arr['site']['seo_desc']);
        $this->assign('siteInfo',$arr['site']);
        $this->sitename = $arr['site']['title'];
        $this->siteseo = $arr['site'];
        $this->setSeo();

        C('DEFAULT_THEME','default');
        $this->assign('banner',getAdsOne(1,$this->siteId));
        $this->assign('q',urldecode(I('get.q')));

    }
    protected function setSeo($info='',$field='title',$q=''){
        if(!empty($info)){
            $info['title'] = isset($info['title']) ? $info['title'] : $info[$field];
            $seo['title'] = empty($info['seo_title']) ? $info[$field].'_'.$this->siteseo['title'] : $info['seo_title'].'_'.$this->siteseo['title'];
            $seo['keys']  = empty($info['seo_keys']) ? $this->siteseo['seo_keys'] : $info['seo_keys'];//$seoarr[$key]['keys'];
            $seo['desc']  = empty($info['seo_desc']) ? $this->siteseo['seo_desc'] : $info['seo_desc'];//$seoarr[$key]['desc'];
        }else{
            $site['title'] = empty($q) ? $this->siteseo['seo_title'].'_'.$this->siteseo['title'] : $q .'_'.$this->siteseo['title'];
            $site['keys']  = $this->siteseo['seo_keys'];
            $site['desc']  = $this->siteseo['seo_desc'];
            $seo = $site;
        }
        $this->assign('seo',$seo);
    }

	private function getSiteId(){

            $this->siteId = 1;


    }
	public function myError(){
        send_http_status(404);
        $this->display('Public:404');
    }
	

    protected function ajaxReturnDialog($status=1, $msg='', $data='', $dialog='') {
        parent::ajaxReturn(array(
            'status' => $status,
            'msg' => $msg,
            'data' => $data,
            'dialog' => $dialog,
        ));
    }
    public function _empty() {
        R('Empty/_empty');
    }
}